def change_heartrate(gpx,coefficient):
    gpx_list=[]
    s=''
    for i in range(len(gpx)):
        s=gpx[i]
        try:
            heart=str((gpx[i].split("<heartrate>")[1]).split("</heartrate>")[0])
            change=int(int(heart)*coefficient)                
            s=str(gpx[i].replace(heart,str(change)))
        except:
            pass
        gpx_list.append(s)
    return gpx_list

def change_time(gpx,coefficient):
    gpx_list=[]
    s=''
    first_time=0
    for i in range(len(gpx)):
        s=gpx[i]
        try:
            ti=str((gpx[i].split("<time>")[1]).split("</time>")[0])
            now_time = time.mktime(time.strptime(ti, "%Y-%m-%dT%H:%M:%SZ"))
            if first_time==0:
                first_time=now_time
                change_time=now_time
            else:
                change_time=((now_time-first_time)*coefficient)+first_time            
            change_time=time.strftime("%Y-%m-%dT%H:%M:%SZ",time.localtime(change_time))  
            s=str(gpx[i].replace(ti,str(change_time)))
        except:
            pass
        gpx_list.append(s)
    return gpx_list

def save_gpx(gpx,path):
    try:
        f=open(path, 'w', encoding="utf-8")
    except:
        f=open(path, 'a', encoding="utf-8")
    for i in gpx:
        f.write(i)
    f.close()
